/**
 * 
 */
package neptune.web.server.operations;

import it.robertobifulco.ias.IncorrectParamsException;
import it.robertobifulco.ias.Operation;
import neptune.manager.connector.Connector;
import neptune.manager.model.cluster.PhysicalNode;
import neptune.manager.model.topology.Node;
import neptune.web.server.ApplicationManager;

/**
 * @author Roberto Bifulco [RobertoBifulco.it] [info@robertoBifulco.it]
 * 
 */
public class PauseNode implements Operation {

	public static String ID = "PauseNode";

	/*
	 * (non-Javadoc)
	 * 
	 * @see it.robertobifulco.ias.Operation#execute(java.lang.Object[])
	 */
	/**
	 * @param args
	 *            [0] = String nodeId - identificativo completo del nodo da
	 *            mettere in pausa
	 * @param args
	 *            [1] = PhysicalNode pm - identificativo della macchina che
	 *            ospita il nodo
	 * @return String lo stato attuale del nodo
	 */
	public Object[] execute(Object[] args) throws IncorrectParamsException,
			Exception {

		String nodeId = (String) args[0];
		PhysicalNode pm = (PhysicalNode) args[1];
		
		if (pm == null)
			throw new Exception("Unable to execute operation because the '"
					+ nodeId + "' hoster was not found.");

		Connector conn = ApplicationManager.getApplicationManager()
				.getNeptuneManager().getConnector(
						pm.getId());

		conn.pauseVM(nodeId);
		conn.closeConnection();

		return new Object[] { Node.Status.PAUSED.toString() };
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see it.robertobifulco.ias.Operation#getDescription()
	 */
	public String getDescription() {
		return "Pauses a given node";
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see it.robertobifulco.ias.Operation#getID()
	 */
	public String getID() {
		return ID;
	}

}
